from langchain_openai import ChatOpenAI
from globle import envs

from langchain_core.runnables import RunnableParallel # 并联的runnable
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser


llm = ChatOpenAI(
    model="deepseek-chat",  # 或具体模型名
    base_url="https://api.deepseek.com/v1",  # DeepSeek API 地址
    temperature = 2.0,
    max_tokens = 32
)
parser = StrOutputParser()

positive_prompt = ChatPromptTemplate.from_template("从积极角度分析{topic}，列举3个优点")
negative_prompt = ChatPromptTemplate.from_template("从批判角度分析{topic}，列举3个缺点")

# 构建并行链
chain = RunnableParallel({
    "positive": positive_prompt | llm | parser,
    "negative": negative_prompt | llm | parser,
})
# 输出参数，是一个字典形式
# key是一个字符串，可把runable组件当作value
# 执行链（所有分支共享同一个输入topic）
result = chain.invoke({"topic": "远程办公"})
print(result)

